package com.lzc.product.controller;

import com.lzc.product.model.Product;
import com.lzc.product.service.ProductService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/addCar.do")
public class AddCatServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Object cId = req.getSession().getAttribute("customerId");
        //如果用户编号为空
        if( cId == null ){
            //跳转到登录页面
            req.getRequestDispatcher("login.jsp").forward(req , resp);
            return;
        }
        String customerId=cId.toString();
        String productId = req.getParameter("productId");
        String number = req.getParameter("number");
        ProductService productService = new ProductService();
        boolean result = productService.addCar(customerId,productId,number);
        System.out.println("购物车情况" + result);
        req.getRequestDispatcher("shopping.html").forward(req , resp);

    }
}
